﻿Public Class UnitExplorer
    Inherits ExplorerTreeList

    Private UnitPL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor

        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If
        '
        Dim guidParent As Guid = Nothing
        Dim guidEnfant As Guid = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
        Dim frmCaption As String = Nothing

        Select Case FocusedNodeLevel
            Case 0
                frmCaption = "Unit List"
                ShowAllUnits()
            Case 1
                If NodeDataRow.Table.Columns.Contains("Code") Then
                    frmCaption = String.Format("{0}", NodeDataRow("Code"))
                Else
                    frmCaption = "Code"
                End If

                ShowByUnit(guidEnfant)
            Case Else
        End Select

        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub

    Public Overridable Sub ShowAllUnits()
        UnitPL = PLBase.CreateInstanceOf(PLTypeOf.Units_PL, "UNITS")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = UnitPL, .SecureGrid = True, .Name = "Unit List", .FormCtrlCD = MyBase.PanelName}

    End Sub

    Public Overridable Sub ShowByUnit(ByVal unitID As System.Guid)
        UnitPL = PLBase.CreateInstanceOf(PLTypeOf.Units_PL, "UNITS")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = UnitPL, .SecureGrid = True, .Name = "Unit List", .FormCtrlCD = MyBase.PanelName}
        UnitPL.SQLWhere = String.Format("UnitId = '{0}'", unitID)
    End Sub

End Class
